package org.bilinc.gz001;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: computer
 * Date: 17.11.12
 * Time: 21:14
 * To change this template use File | Settings | File Templates.
 */
public class FooterRenderer extends DefaultTableCellRenderer {
    private static final Color FIELD_COLOR = new Color(255, 255, 204);
    private static final int TECH = 0;
    private static final int ATIM = 1;
    private static final int EVS = 2;
    private static final int MRS = 3;
    private static final int OKS = 4;
    private static final int DAY = 5;
    private static final int NIGHT = 6;
    private static final int WEEKENDS_V = 7;
    private static final int WEEKENDS_M = 8;
    private static final int TOTAL_S = 9;
    private static final int TOTAL_V = 10;

    public Component getTableCellRendererComponent(JTable table,
                                                   Object obj, boolean isSelected, boolean hasFocus, int row, int column) {
        final Component cell = super.getTableCellRendererComponent(
                table, obj, isSelected, hasFocus, row, column);
        if (isSelected) {

        } else {
            boolean isSunday = ((column + 2 > 6) &&
                                (column + 2) % 7 == 0) || column + 1 == 6;
            switch (row) {
                case TECH:
                    if (isSunday) {
                        cell.setBackground(Color.YELLOW);
                    } else {
                        cell.setBackground(Color.LIGHT_GRAY);
                    }
                    break;
                case ATIM:
                    if (isSunday) {
                        cell.setBackground(Color.YELLOW);
                    } else {
                        cell.setBackground(Color.cyan);
                    }
                    break;
                case EVS:
                    if (isSunday) {
                        cell.setBackground(Color.YELLOW);
                    } else {
                        cell.setBackground(Color.LIGHT_GRAY);
                    }
                    break;
                case MRS:
                    if (isSunday) {
                        cell.setBackground(Color.YELLOW);
                    } else {
                        cell.setBackground(Color.cyan);
                    }
                    break;
                case OKS:
                    if (isSunday) {
                        cell.setBackground(Color.YELLOW);
                    } else {
                        cell.setBackground(Color.LIGHT_GRAY);
                    }
                    break;
                case DAY:

                    break;
                case NIGHT:
                    cell.setBackground(new Color(58, 159, 244));
                    break;
                case WEEKENDS_V:
                    cell.setBackground(FIELD_COLOR);
                    break;
                case WEEKENDS_M:
                    cell.setBackground(FIELD_COLOR);
                    break;
                case TOTAL_S:
                    cell.setBackground(Color.cyan);
                    break;
                case TOTAL_V:
                    cell.setBackground(Color.cyan);
                    break;
            }
        }
        if (obj != null) {
            if (obj.equals("0")) {
                cell.setBackground(Color.RED);
            }
        }
        return cell;
    }
}
